package org.rency.crawler.common.enums;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 抓取策略
 *
 * @author: user_rcy@163.com <br>Created on 2015年12月5日
 * @version: V1.0.0
 * @since JDK 1.8
 */
public enum FetchPolicy {

  BREADTH("BREADTH", "广度优先"),
  DEPTH("DEPTH", "深度优先"),;

  private String code;
  private String msg;

  private FetchPolicy(String code, String msg) {
    this.code = code;
    this.msg = msg;
  }

  public String getCode() {
    return this.code;
  }

  public String getMsg() {
    return this.msg;
  }

  public static FetchPolicy get(String code) {
    if (StringUtils.isBlank(code)) {
      return null;
    }
    for (FetchPolicy ek : FetchPolicy.values()) {
      if (ek.getCode().toUpperCase().equals(code.toUpperCase())) {
        return ek;
      }
    }
    throw new IllegalArgumentException("未知的状态码:" + code);
  }

  public static String get(FetchPolicy method) {
    if (method == null) {
      return null;
    }
    return method.getCode();
  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  }
}